﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using AvalonDock.Layout;
using GalaSoft.MvvmLight.Messaging;
using Daphne.Presenters;
using DaphneProfiBase;
using AvalonDock.Controls;
using System.Reflection;


namespace DaphneControls
{
    /// <summary>
    /// Code-behind for checkers board
    /// </summary>
    public partial class CheckersBoard : UserControl
    {
        private const string sPicturePath = "AppData/Pictures";

        public CheckersBoard()
        {
            InitializeComponent();

            // register message for gaining presenter
            Messenger.Default.Register<NotificationMessage<ProfessionalGameBoardPresenter>>(this, (nm) =>
                {
                    if (nm.Notification == Notify.SetPresenter && nm.Sender == this.DataContext)
                    {
                        string sAppPath = Assembly.GetExecutingAssembly().Location;
                        sAppPath = System.IO.Path.GetDirectoryName(sAppPath);

                        uxBoard2D.SetPresenter(nm.Content);

                        string sImagePath = System.IO.Path.Combine(sAppPath, sPicturePath);
                        uxBoard2D.LoadImages(sImagePath);
                    }
                });

            // register message for redrawing the board
            Messenger.Default.Register<NotificationMessage>(this, (nm) =>
                {
                    if (nm.Notification == Notify.RedrawCheckersBoard && nm.Sender == this.DataContext)
                    {
                        uxBoard2D.InvalidateVisual();
                    }
                });           
        }
    }
}
